package com.example.superoa.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.Rbiographical;
import com.example.superoa.model.service.RbiographicalService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class RbiographicaController {
			@Autowired
			private RbiographicalService bioservice;		
			//根据名字模糊查询简历	
			@PostMapping("select-resume")
			@ResponseBody
			public Map<String,Object> show(String reasyname,int reasyid,int page,int rows) {
				System.out.println(reasyname);
				Map<String,Object> map = new HashMap<>();
				//先分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray j =null ;
				if(reasyid==1) {
					j=bioservice.biofindAll();
				}else {
					j=bioservice.findByName(reasyname);
				}
				int i=1;
				for (Object object : j) {
					JSONObject obj=(JSONObject)object;
					obj.put("biogra", i);
					i++;
				}
				//总记录
				map.put("total", pg.getTotal());
				//页内容
				map.put("rows", j);
				return map;
			}
			@RequestMapping("zxcvb")
			@ResponseBody
			public JSONArray  ss() {
				return bioservice.findByName(null);				
			}
			/**新增
			 * @return
			 */
			@RequestMapping("recruitinserts")
			@ResponseBody
			public String recruitinsert(Rbiographical biographical,Integer position_id,Integer rapplyid) {
				bioservice.insertrbiographical(biographical,position_id,rapplyid);
				return "redirect:main-administrator:recruitbiographical";				
			}
			//点击查看详情显示
			@RequestMapping("bio-xiangq")
			@ResponseBody
			public JSONArray bioxiangq(int reasyid) {
				return bioservice.findByIdbio(reasyid);
			}
			//初始化
			@RequestMapping("bio-allbio")
			@ResponseBody
			public JSONArray selectallbio(int reasyid) {		
				JSONArray json = bioservice.findByIdbio(reasyid);
				return json;
			}
			//修改
			@RequestMapping("bio-xiugais")
			@ResponseBody
			public void xiugaibio(int reasyid,Date reasytime) {
				System.err.println("接收到"+reasyid+".."+reasytime);
				bioservice.xiugaibio(reasyid, reasytime);
			}		
			//面试通知		结果
			@RequestMapping("email")
			@ResponseBody
			public int email(Integer id,Integer rid) {
				return bioservice.tongzhi(id, rid);
			}	
			//查询计划申请
			@RequestMapping("select_apply")
			@ResponseBody
			public JSONArray selectapply(){
				JSONArray json=bioservice.selectapply();
				int i=1;
				for (Object object : json) {
					JSONObject obj=(JSONObject)object;
					obj.put("sortable", i);
					i++;
				}
				return json;
			}
}